import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class BusinessStrategyService {

  constructor(
    private httpClient: HttpClient,
  ) {
  }

  // 获取文章分类
  getArticleCategory() {
    return this.httpClient.post('/userShopsStrategy/list', {page: 1, pageSize: 9999}).toPromise();
  }

  // 编辑文章分类
  editCategory(id: any, classifyName: any) {
    id = id !== null ? '/' + id : '';
    classifyName = classifyName !== null ? '/' + classifyName : '';
    return this.httpClient.get(`/userShopsStrategy${id}${classifyName}`).toPromise();
  }

  // 删除文章分类
  deleteCategory(id: any) {
    return this.httpClient.delete(`/userShopsStrategy/${id}`).toPromise();
  }

  // 获取文章列表
  getArticle(body: any) {
    return this.httpClient.post('/userShopsStrategy/essay', body).toPromise();
  }

  // 删除文章
  deleteArticle(id: any) {
    return this.httpClient.delete('/userShopsStrategy/essay/' + id).toPromise();
  }

  // 添加文章
  addArticle(body: any) {
    return this.httpClient.post('/userShopsStrategy/addEssay', body).toPromise();
  }

  // 编辑文章
  editArticle(body: any) {
    return this.httpClient.post('/userShopsStrategy/updateEssay', body).toPromise();
  }

  // 移动文章
  moveArticle(id: any, type: any) {
    // 1.上移 2.下移
    return this.httpClient.post('/userShopsStrategy/move', {id, type}).toPromise();
  }
}
